package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtOrg;
import com.ruoyi.prt.service.IPrtOrgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 组织Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/org")
public class PrtOrgController extends BaseController
{
    @Autowired
    private IPrtOrgService prtOrgService;

    /**
     * 查询组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:org:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtOrg prtOrg)
    {
        startPage();
        List<PrtOrg> list = prtOrgService.selectPrtOrgList(prtOrg);
        return getDataTable(list);
    }

    /**
     * 导出组织列表
     */
    @PreAuthorize("@ss.hasPermi('system:org:export')")
    @Log(title = "组织", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtOrg prtOrg)
    {
        List<PrtOrg> list = prtOrgService.selectPrtOrgList(prtOrg);
        ExcelUtil<PrtOrg> util = new ExcelUtil<PrtOrg>(PrtOrg.class);
        return util.exportExcel(list, "org");
    }

    /**
     * 获取组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:org:query')")
    @GetMapping(value = "/{orgId}")
    public AjaxResult getInfo(@PathVariable("orgId") String orgId)
    {
        return AjaxResult.success(prtOrgService.selectPrtOrgById(orgId));
    }

    /**
     * 新增组织
     */
    @PreAuthorize("@ss.hasPermi('system:org:add')")
    @Log(title = "组织", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtOrg prtOrg)
    {
        return toAjax(prtOrgService.insertPrtOrg(prtOrg));
    }

    /**
     * 修改组织
     */
    @PreAuthorize("@ss.hasPermi('system:org:edit')")
    @Log(title = "组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtOrg prtOrg)
    {
        return toAjax(prtOrgService.updatePrtOrg(prtOrg));
    }

    /**
     * 删除组织
     */
    @PreAuthorize("@ss.hasPermi('system:org:remove')")
    @Log(title = "组织", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orgIds}")
    public AjaxResult remove(@PathVariable String[] orgIds)
    {
        return toAjax(prtOrgService.deletePrtOrgByIds(orgIds));
    }
}
